﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using MyQuestMobApp.TeacherService;


namespace MyQuestMobApp.pages
{
    public partial class offline_tracking : PhoneApplicationPage
    {
        public List<WP7Phone> dataSource;
        public List<GAME> gameDataSource;
        public int student_id;
        public int game_id;
        public List<Student_Progresses> spResult;
        public offline_tracking()
        {
            InitializeComponent();
            dataSource = new List<WP7Phone>() 
			{
			new WP7Phone(){Image="../images/1.jpg", Name = "Jack Hopkins" , student_id=15},
			new WP7Phone(){Image="../images/2.jpg", Name = "Maria Taylor", student_id=8},
			new WP7Phone(){Image="../images/3.jpg", Name = "Jason Ross",student_id=6},
            new WP7Phone(){Image="../images/4.jpg", Name = "Janaton Manson",student_id=3},
			
			};
            this.acBox.ItemsSource = dataSource;

            gameDataSource = new List<GAME>() 
			{
			new GAME(){Image="../images/electro_negativity.png", Name = "Electro negativity" , game_id=5},
			new GAME(){Image="../images/crime_scene.gif", Name = "Crime Scene", game_id=4},
			
			};
            this.gameBox.ItemsSource = gameDataSource;
        }

        bool SearchStudent(string search, object value)
        {
            if (value != null)
            {
                WP7Phone datasourceValue = value as WP7Phone;
                string name = datasourceValue.Name;

                if (name.ToLower().StartsWith(search.ToLower()))
                    return true;
            }
            //... If no match, return false. 
            return false;
        }

        private void acBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (WP7Phone iterator in dataSource)
            {
                if (iterator.Name == acBox.Text)
                    student_id = iterator.student_id;
            }
        }

        private void gameBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (GAME iterator in gameDataSource)
            {
                if (iterator.Name == gameBox.Text)
                    game_id = iterator.game_id;
            }
        }

        private void showProgress_btn_Click(object sender, RoutedEventArgs e)
        {
            var teacherSrvClient = new TeacherSrvClient();
            teacherSrvClient.getStudentProgressCompleted += new EventHandler<getStudentProgressCompletedEventArgs>(client_getStudentProgressCompleted);
            teacherSrvClient.getStudentProgressAsync(student_id,game_id);
            

        }

        private void client_getStudentProgressCompleted(Object sender, getStudentProgressCompletedEventArgs e)
        {
            spResult = e.Result.ToList();
            this.Content = new studentProgress_result(spResult);
        }
    }



    public class WP7Phone
    {

        public string Image
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        public int student_id
        {
            get;
            set;
        }

        //public override string ToString()
        //{
        //    return "Selected Phone: " +Name;
        //}
    }

    public class GAME
    {

        public string Image
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        public int game_id
        {
            get;
            set;
        }

        //public override string ToString()
        //{
        //    return "Selected Phone: " +Name;
        //}
    }

}